/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __8263035E_5754_4DEE_A8E8_267505BC5382__
#define __8263035E_5754_4DEE_A8E8_267505BC5382__

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

namespace xos_box
{
    class i_int_property;
}

namespace xos_common
{

    ///////////////////////////////////////////////////////////////////////////////////////////////////////
    // 
    // misc
    // 
    class i_misc : public xos::i_release
    {
    protected:
        virtual ~i_misc(){}

    public:
        // 以指定进制显示数据内容 : 16, 10, 8
        virtual int bin_to_text( char * lpszOutData, int nOutLen, int * pnOutLen, const unsigned char * lpszInData, int nInLen, int decimal ) = 0;

        virtual int DoDES( char * Out, const char * In, long datalen, const char * Key, int keylen, bool bEncode ) = 0;

        virtual unsigned short cal_crc16( const unsigned char * lpData, int nLen ) = 0;

        virtual int url_encode( const char * lpszSrc, int nSrcLen, char * lpszDst, int nCharNum ) = 0;
        virtual int url_decode( const char * lpszSrc, int nSrcLen, char * lpszDst, int nCharNum ) = 0;

        virtual int base64_encode( const char * lpszSrc, int nSrcLen, char * lpszDst, int nCharNum ) = 0;
        virtual int base64_decode( const char * lpszSrc, int nSrcLen, char * lpszDst, int nCharNum ) = 0;

        // 
        // 计算分页的url
        // 
        virtual int page_info( int nMaxPage, int nPageNum, int nCurPage, bool bEnable, char * lpszPageInfoUrl, int nBufSize, int * lpnInfoSize ) = 0;

        // 
        // 字串操作
        // 
        virtual const char * split_full_file( const char * lpszFullFile, char * lpszPath, int nSize, int * lpnSize ) = 0;
        virtual const char * ext( const char * lpszFile, xos_box::i_string * pStr ) = 0;
        virtual int parse_uri_to_property( const char * lpszUri, xos_box::i_int_property * pProp ) = 0;
        // \t -> \\t, ' -> \\', " -> \\"
        virtual int trans( const char * lpszSrc, char * lpszDst, int nLen, int * lpnLen ) = 0;
        virtual int begin_with( const char * lpszStr, const char * lpszSub ) = 0;
        virtual int end_with( const char * lpszStr, const char * lpszSub ) = 0;
        virtual int trim( char * lpszStr, const char * lpszTrims ) = 0;
        virtual int valid( const char * lpszStr, int nLen ) = 0;

        virtual int str_split( char* lpszUrl, const char seperator = '/' ) = 0;

        // 
        // 拷贝文件
        // 
        virtual int copy( const char * lpszSrcFile, const char * lpszDstFile ) = 0;

		// 
		// 常用判断方法
		// 
		virtual bool is_valid_email_addr( const char * lpszEmail ) = 0;
		virtual bool is_valid_id_card( const char * lpszIdCard ) = 0;
        virtual bool is_valid_phone( const char * lpszPhone ) = 0;

        // 
        // 数值数据
        // 
        virtual bool approximately_equal( double a, double b, double epsilon = 1e-8 ) = 0;
        virtual bool essentially_equal( double a, double b, double epsilon = 1e-8 ) = 0;
        virtual bool definitely_greater( double a, double b, double epsilon = 1e-8 ) = 0;
        virtual bool definitely_less( double a, double b, double epsilon = 1e-8 ) = 0;
        virtual int double_compare( double a, double b ) = 0;

        // 
        // endian
        // 
        virtual uint64_t to_small_endian_64( uint64_t value ) = 0;
        virtual uint64_t to_big_endian_64( uint64_t value ) = 0;

        virtual uint32_t to_small_endian_32( uint32_t value ) = 0;
        virtual uint32_t to_big_endian_32( uint32_t value ) = 0;

        virtual uint64_t to_small_endian_64( double value ) = 0;
        virtual uint64_t to_big_endian_64( double value ) = 0;

        virtual uint32_t to_small_endian_32( float value ) = 0;
        virtual uint32_t to_big_endian_32( float value ) = 0;

        virtual uint64_t swap_endian_64( uint64_t value ) = 0;
        virtual uint32_t swap_endian_32( uint32_t value ) = 0;

        virtual bool is_small_endian() = 0;

    };

} // xos_common

#endif // __8263035E_5754_4DEE_A8E8_267505BC5382__
